package com.globefrog.example.provider.service;

import com.globefrog.example.entity.User;
import com.globefrog.example.provider.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author : Globe-Frog
 * @date : Create in 2021/7/8
 */
@Slf4j
@Service
public class UserService {

  @Autowired
  private UserMapper userMapper;

  public User getById(String id) {
    return userMapper.selectById(id);
  }

  public void insert(User user) {
    userMapper.insert(user);
  }

  public void update(User user) {
    // user的值为需要更新的字段内容
    userMapper.updateById(user);
    // 根据条件设置
    //UpdateWrapper<User> condition = new UpdateWrapper<>();
    //condition.eq("name", user.getName());
    //User set = new User();
    //set.setAge(18);
    //Integer rows = userMapper.update(user, condition);
    // set构造器
    // UpdateWrapper<User> updateWrapper = new UpdateWrapper<>();
    // updateWrapper.eq("name","shimin").set("age", 35);
    // Integer rows = userMapper.update(null, updateWrapper);
  }

  public void delete(Long id) {
    userMapper.deleteById(id);
  }
}
